<?php

declare(strict_types=1);

namespace Modules\Purchasing\Models;

use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class Provisionalschedule extends Model
{
    

    protected $table = 'provisionalschedule';
    // protected $casts = [ 
    //     'supplierschedule_id' => 'array',  
    // ]; 
    protected $fillable = [ 'id', 'creator_id', 'created_at', 'updated_at', 'deleted_at' , 'purchaseorder_id', 'purchaseorderschedule_id','supplier_id','supplierschedule_id', 'quantity', 'quantityreceived','barcode','storagelocation','provisional_id','giveaway','putquantity','purchasewarehousing_id','caigoucreator_id','inspectionlisttable_id','storagelocation_id','fields1','fields2','fields3','fields4','fields5','fields6','fields7','fields8','fields9','fields10'];

    /**
     * @var array
     */
    protected array $fields = ['id', 'creator_id','created_at','updated_at', 'deleted_at', 'purchaseorder_id', 'purchaseorderschedule_id', 'supplier_id','supplierschedule_id', 'quantity', 'quantityreceived','barcode','storagelocation','provisional_id','giveaway','putquantity','purchasewarehousing_id','caigoucreator_id','inspectionlisttable_id','storagelocation_id','fields1','fields2','fields3','fields4','fields5','fields6','fields7','fields8','fields9','fields10'];

    /**
     * @var array
     */
    protected array $form = ['id', 'creator_id','created_at','updated_at', 'deleted_at', 'purchaseorder_id','purchaseorderschedule_id', 'supplier_id', 'supplierschedule_id', 'quantity', 'quantityreceived','barcode','storagelocation','provisional_id','giveaway','putquantity','purchasewarehousing_id','caigoucreator_id','inspectionlisttable_id','storagelocation_id','fields1','fields2','fields3','fields4','fields5','fields6','fields7','fields8','fields9','fields10'];

      /**
     * @var array
     */
    public array $searchable = [
        'quantityreceived' => 'like',
        'barcode' => 'like',
        'storagelocation' => 'like',
    ];
    
    //输出相应的时间格式
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

     /**
     * 链表查询
     */
    public function detailscheckOne()
    {
        return $this->hasOne(Supplierschedule::class);//查一条
    }

    public function detailscheckAll()
    {
        return $this->hasMany(Supplierschedule::class);//查多条
    }

    public function inspectionlistcheckAll()
    {
        return $this->hasMany(Inspectionlistcheck::class);//查多条
    }


    //打印链表
    public function BarcodeprintingAll()
    {
        return $this->hasMany(Barcodeprinting::class);//查多条
    }

    public static function getData($fields,$where){
        return self::select($fields)->where($wheredata)->first();
    }

    public static function getDatajon($fields,$where){
        return self::select($fields)
        ->join('provisional as provisional','provisional.id','=','provisionalschedule.provisional_id')
        ->where($where)->first();
    }

    public static function getDatajoninspection($fields,$where){
        
        return self::select($fields)
        ->join('inspectionlisttable as inspectionlisttable','inspectionlisttable.id','=','provisionalschedule.inspectionlisttable_id')
        ->where($where)->where('inspectionlisttable.state',1)->first();
    }

    public static function getDatajoninpurchasewa($fields,$where){
        return self::select($fields)
        ->join('purchasewarehousing as purchasewarehousing','purchasewarehousing.id','=','provisionalschedule.purchasewarehousing_id')
        ->where($where)->first();
    }

    
}
